import java.io.*;


public class TextDealer {
    private String sourceFile;
    private String targetFile;
    TextDealer(String sourceFile,String targetFile){
        this.sourceFile = sourceFile;
        this.targetFile = targetFile;
    }

    public String readByFileReader() throws Exception{
        Reader reader = null;
        try{
            StringBuffer buf = new StringBuffer();
            char[] chars = new char[1024];
            reader = new FileReader(this.sourceFile);
            int readed = reader.read(chars);
            while(readed != -1){
                buf.append(chars,0,readed);
                readed = reader.read(chars);
            }
            return buf.toString();
        }
        finally {
            if(reader != null) reader.close();
        }
    }

    public void writeIntoTxt(String [] outputContent) throws Exception{
        Writer writer = null;
        try {
//            writer = new FileWriter(new File("."));
            writer = new FileWriter(this.targetFile);
            for(String str:outputContent) {
                writer.write(str.toCharArray());
            }
        }finally {
            if(writer != null) writer.close();
        }
    }

}
